﻿<!--
Filename: Generic.xaml
Version: 20130314
-->

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:ImageButtons"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">
  
  <!-- ImageButton -->

  <ControlTemplate x:Key="ImageButtonTemplate" TargetType="local:ImageButton">
    <Grid Background="{TemplateBinding Background}">
      <VisualStateManager.VisualStateGroups>
        <VisualStateGroup x:Name="CommonStates">
          <VisualStateGroup.Transitions>
            <VisualTransition GeneratedDuration="0:0:0.1">
              <VisualTransition.GeneratedEasingFunction>
                <CubicEase EasingMode="EaseOut"/>
              </VisualTransition.GeneratedEasingFunction>
            </VisualTransition>
          </VisualStateGroup.Transitions>
          <VisualState x:Name="Normal"/>
          <VisualState x:Name="MouseOver">
            <Storyboard>
              <DoubleAnimation To="1" Duration="0" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="ImageHover" d:IsOptimized="True"/>
            </Storyboard>
          </VisualState>
          <VisualState x:Name="Pressed"/>
          <VisualState x:Name="Disabled"/>
        </VisualStateGroup>
      </VisualStateManager.VisualStateGroups>
      <Image x:Name="Image" Source="{TemplateBinding Image}" Stretch="None"/>
      <Image x:Name="ImageHover" Source="{TemplateBinding ImageHover}" Stretch="None" Opacity="0"/>
    </Grid>
  </ControlTemplate>

  <Style TargetType="local:ImageButton">
    <Setter Property="Cursor" Value="Hand"/>
    <Setter Property="Template" Value="{StaticResource ImageButtonTemplate}"/>
  </Style>


  <!-- ImageToggleButton -->

  <ControlTemplate x:Key="DefaultImageToggleButtonTemplate" TargetType="local:ImageToggleButton">
    <Grid Background="{TemplateBinding Background}">
      <VisualStateManager.VisualStateGroups>
        <VisualStateGroup x:Name="CommonStates">
          <VisualStateGroup.Transitions>
            <VisualTransition GeneratedDuration="0:0:0.1">
              <VisualTransition.GeneratedEasingFunction>
                <CubicEase EasingMode="EaseOut"/>
              </VisualTransition.GeneratedEasingFunction>
            </VisualTransition>
          </VisualStateGroup.Transitions>
          <VisualState x:Name="Normal"/>
          <VisualState x:Name="MouseOver">
            <Storyboard>
              <DoubleAnimation To="0.5" BeginTime="0" Duration="0" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="ImageHover"/>
              <DoubleAnimation To="0.5" BeginTime="0" Duration="0" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="ImageCheckedHover"/>
            </Storyboard>
          </VisualState>
          <VisualState x:Name="Unchecked">
            <Storyboard>
              <DoubleAnimation To="1" BeginTime="0" Duration="0" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="Image"/>
              <DoubleAnimation To="0" BeginTime="0" Duration="0" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="ImageChecked"/>
            </Storyboard>
          </VisualState>
          <VisualState x:Name="Checked">
            <Storyboard>
              <DoubleAnimation To="0" BeginTime="0" Duration="0" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="Image"/>
              <DoubleAnimation To="1" BeginTime="0" Duration="0" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="ImageChecked"/>
            </Storyboard>
          </VisualState>
          <VisualState x:Name="Pressed"/>
          <VisualState x:Name="Disabled"/>
        </VisualStateGroup>
      </VisualStateManager.VisualStateGroups>
      <Image x:Name="Image" Source="{TemplateBinding Image}" Stretch="None" />
      <Image x:Name="ImageChecked" Source="{TemplateBinding ImageChecked}" Stretch="None" />
      <Image x:Name="ImageHover" Source="{TemplateBinding ImageHover}" Stretch="None" Opacity="0" />
      <Image x:Name="ImageCheckedHover" Source="{TemplateBinding ImageCheckedHover}" Stretch="None" Opacity="0" />
    </Grid>
  </ControlTemplate>

  <Style TargetType="local:ImageToggleButton">
    <Setter Property="Cursor" Value="Hand"/>
    <Setter Property="Template" Value="{StaticResource DefaultImageToggleButtonTemplate}"/>
  </Style>

  <!-- ImageToggleButtonSideBySide -->

  <ControlTemplate x:Key="DefaultImageToggleButtonSideBySideTemplate" TargetType="local:ImageToggleButtonSideBySide">
      <StackPanel Orientation="Horizontal" Background="{TemplateBinding Background}">
        <VisualStateManager.VisualStateGroups>
          <VisualStateGroup x:Name="CommonStates">
            <VisualStateGroup.Transitions>
              <VisualTransition GeneratedDuration="0:0:0.1">
                <VisualTransition.GeneratedEasingFunction>
                  <CubicEase EasingMode="EaseOut"/>
                </VisualTransition.GeneratedEasingFunction>
              </VisualTransition>
            </VisualStateGroup.Transitions>
            <VisualState x:Name="Normal"/>
            <VisualState x:Name="MouseOver">
              <Storyboard>
                <DoubleAnimation To="1" BeginTime="0" Duration="0" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="ImageHover"/>
                <DoubleAnimation To="1" BeginTime="0" Duration="0" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="ImageCheckedHover"/>
              </Storyboard>
            </VisualState>
            <VisualState x:Name="Unchecked">
              <Storyboard>
                <DoubleAnimation To="1" BeginTime="0" Duration="0" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="ImageSelector"/>
                <DoubleAnimation To="0" BeginTime="0" Duration="0" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="ImageCheckedSelector"/>
              </Storyboard>
            </VisualState>
            <VisualState x:Name="Checked">
              <Storyboard>
                <DoubleAnimation To="0" BeginTime="0" Duration="0" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="ImageSelector"/>
                <DoubleAnimation To="1" BeginTime="0" Duration="0" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="ImageCheckedSelector"/>
              </Storyboard>
            </VisualState>
            <VisualState x:Name="Pressed"/>
            <VisualState x:Name="Disabled"/>
          </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
        <Grid>
          <Image x:Name="ImageSelector" Source="{TemplateBinding ImageSelector}" Stretch="None" Opacity="1" />
          <Image x:Name="Image" Source="{TemplateBinding Image}" Stretch="None" />
          <Image x:Name="ImageHover" Source="{TemplateBinding ImageHover}" Stretch="None" Opacity="0" />
        </Grid>
        <Grid>
          <Image x:Name="ImageCheckedSelector" Source="{TemplateBinding ImageSelector}" Stretch="None" Opacity="0" />
          <Image x:Name="ImageChecked" Source="{TemplateBinding ImageChecked}" Stretch="None" />
          <Image x:Name="ImageCheckedHover" Source="{TemplateBinding ImageCheckedHover}" Stretch="None" Opacity="0" />
        </Grid>
      </StackPanel>
    </ControlTemplate>

  <Style TargetType="local:ImageToggleButtonSideBySide">
    <Setter Property="Cursor" Value="Hand"/>
    <Setter Property="Template" Value="{StaticResource DefaultImageToggleButtonSideBySideTemplate}"/>
  </Style>
  
</ResourceDictionary>
